package com.safe.ele.service.impl;


import com.safe.ele.dao.IOrderDao;
import com.safe.ele.dto.UserOrderDto;
import com.safe.ele.entity.IOrder;
import com.safe.ele.service.intf.IOrderService;
import com.safe.ele.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
/**
 * @program: springboot
 * @description: 十一组后端源码
 * @author: Feri(十一组)
 * @create: 2021-01-09 17:39:00
 */
@Service
public class IOrderServiceImpl implements IOrderService {
    /*
    *注入持久层对象*/
    @Autowired
    private IOrderDao dao;
    /*
    * 新增内容*/
    @Override
    public R save(IOrder iOrder) {
        if(iOrder!=null){
            iOrder.setStatus(1);
            if(dao.insert(iOrder)>0){
                return R.ok();
            }
        }
        return R.fail("新增异常");
    }
    /*
    * 查询 所有数据*/
    @Override
    public R queryAll(int id) {

        if(id>0){
            List<UserOrderDto> userOrderDtos = dao.selectAll(id);
            return R.ok(userOrderDtos) ;
        }
        return R.fail("参数未传递");
    }

    /*
     * 删除 根据ID*/
    @Override
        public R DelAll(IOrder iOrder) {
           if(iOrder!=null){
                       if(dao.DelAll(iOrder)>0){
                           return R.ok();
                       }
                   }
                   return R.fail("删除异常");
        }

      /*
      * 根据ID跟新数据*/
     @Override
         public R updateById(IOrder iOrder) {
            if(iOrder!=null){
                   if(dao.updateById(iOrder)>0){
                         return R.ok();
                      }
                 }
                  return R.fail("跟新异常");
          }

      /*
         * 模糊查询数据*/
         @Override
         public List<IOrder> selectMhcx (IOrder iOrder,Integer page, Integer limit) {
             PageHelper.startPage(page, limit);
             return dao.selectMhcx(iOrder);

            }

      /*
          * 根据ID查询数据*/
          @Override
          public R selectById(IOrder iOrder) {
              return R.ok(dao.selectById(iOrder));
          }

     /*
     * 批量删除数据*/
         @Override
         public R deleteByIds(IOrder iOrder,String ids) {
             if(iOrder!=null){
             String[] arr = ids.split(",");
             List<Integer> list = new ArrayList<>();
             for (int i = 0; i < arr.length; i++) {
                    list.add(Integer.parseInt(arr[i]));
                }

                 if(dao.deleteByIds(list)>0){
                         return R.ok();
             }
         }
                  return R.fail("批量删除异常");
     }

}